
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation
**
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
**     the names of its contributors may be used to endorse or promote
**     products derived from this software without specific prior written
**     permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
** $QT_END_LICENSE$
**
****************************************************************************/



// System Include.
#include <e32def.h>

//! User Include.
#include "descriptors.h"

/*!
 * Constructor, creates the buffer and CDescriptorExamples object.
 */
Descriptors::Descriptors()
{
    iBuffer = HBufC::NewL(4096);
    d_ptr = new (ELeave) CDescriptorExamples( this );
}

/*!
 * Destructor.
 */
Descriptors::~Descriptors()
{
    delete d_ptr;
    d_ptr = NULL;

    delete iBuffer;
    iBuffer = NULL;
}

/*!
 * Returns a modifiable descriptor pointer to the internal buffer so that descriptor
 * operations can write their results to it.
 */
TPtr Descriptors::GetViewBuffer()
{
    return iBuffer->Des();
}

/*!
 * Converts the symbian based internal buffer into a Qt based string, and
 * then emits a signal to print the result on the screen.
 */
void Descriptors::UpdateView()
    {
    QString msg((QChar*)iBuffer->Des().Ptr(),iBuffer->Length());
    message = msg;
    emit printMessage();
    }

/*!
 * Returns the Qt based string, holding the descriptor operation results.
 */
QString Descriptors::showResponse()
{
    return message;
}

/*!
 * Calls the example method, that describes how descriptor allocation and deallocation
 * is done on "Stack".
 */
void Descriptors::createOnStack()
{
    iBuffer->Des().SetLength(0);
    d_ptr->OnStack();
}

/*!
 * Calls the example method, that describes how descriptor allocation is
 * done on "Heap".
 */
void Descriptors::createOnHeap()
{
    iBuffer->Des().SetLength(0);
    d_ptr->OnHeapL();
}

/*!
 * Calls the example method, that describes how to declare "Literals".
 */
void Descriptors::createLiterals()
{
    iBuffer->Des().SetLength(0);
    d_ptr->Literals();
}

/*!
 * Calls the example method, that demonstrates the usage of non-modifying methods
 * declared by the base class of all descriptor, TDesC.
 */
void Descriptors::callNonModifyingMethods()
{
    iBuffer->Des().SetLength(0);
    d_ptr->NonModifyingMethods();
}

/*!
 * Calls the example method, that demonstrates the usage of modifying methods
 * declared by the base class of modifying descriptors, TDes.
 */
void Descriptors::callModifyingMethods()
{
    iBuffer->Des().SetLength(0);
    d_ptr->ModifyingMethodsL();
}

/*!
 * Calls the example method, that demonstrates how to convert string data encoded
 * with one character set to unicode and vice versa.
 */
void Descriptors::callCharacterConversions()
{
    iBuffer->Des().SetLength(0);
    d_ptr->CharacterConversionsL();
}

/*!
 * Calls the example method, that demonstrates how numbers in string format can
 * be parsed to binary representation.
 */
void Descriptors::doLexicalAnalysis()
{
    iBuffer->Des().SetLength(0);
    d_ptr->LexicalAnalysis();
}

/*!
 * Calls the example method, that demonstrates how circular buffer,
 * is used to manipulate character data.
 */
void Descriptors::useCircularBuffers()
{
    iBuffer->Des().SetLength(0);
    d_ptr->CircularBuffersL();
}

/*!
 * Calls the example method, that demonstrates how flat dynamic buffer
 * (CBufFlat) is used to store and alter binary data.
 */
void Descriptors::useFlatDynamicBuffers()
{
    iBuffer->Des().SetLength(0);
    d_ptr->FlatDynamicBuffersL();
}

/*!
 * Calls the example method, that demonstrates how segmented dynamic buffers
 * (CBufSeg) are used to store and alter binary content.
 */
void Descriptors::useSegmentedDynamicBuffers()
{
    iBuffer->Des().SetLength(0);
    d_ptr->SegmentedDynamicBuffersL();
}

/*!
 * Calls the example method, that demonstrates how to declare and use package
 * buffers and package pointers.
 */
void Descriptors::usePackageBuffers()
{
    iBuffer->Des().SetLength(0);
    d_ptr->PackageBuffers();
}

/*!
 * Calls the example method, that demonstrates different usages of RBuf.
 */
void Descriptors::callRBufDemonstrations()
{
    iBuffer->Des().SetLength(0);
    d_ptr->RBufDemonstrations();
}
